<%@ page contentType="text/html; charset=UTF-8" errorPage="/jsp/error.jsp" %>
<%@ taglib uri="/WEB-INF/tlds/struts-html.tld"  prefix="html" %>
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld"  prefix="bean" %>
<%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/tlds/custom-html.tld" prefix="chtml" %>

<%@ page  import="java.util.ArrayList" %>
<%@ page  import="java.sql.Timestamp" %>

<%@ page  import="com.erp.framework.util.CommonUtil" %>
<%@ page  import="com.erp.app.admin.systemMenu.beans.SystemMenuGroupVO" %>
<%@ page  import="com.erp.app.admin.systemMenu.web.SystemMenuMaintenanceForm" %>
<%@ page  import="com.erp.app.admin.systemMenu.web.SystemMenuObjectRow" %>
<%@ page  import="com.erp.app.common.ProjectConstants" %>
<%@ page  import="com.erp.app.util.web.WebUtil" %>
<%@ page  import="com.erp.framework.util.logger.Logger" %>


<jsp:useBean id="systemMenuMaintenanceForm" scope="session" type="com.erp.app.admin.systemMenu.web.SystemMenuMaintenanceForm" />

<%
ArrayList menuObjectList = systemMenuMaintenanceForm.getMultiRows(0);
pageContext.setAttribute("menuObjectList", menuObjectList);

System.out.println("****** systemMenuMaintenanceForm.menuObjectList.size() =[" + menuObjectList.size() + "]");

%>

<script language="javascript">

//view function
function doViewIcon() {
    window.open("systemMenuMaintenance.do?pageEvent=viewMenuGroupIcon", "wdis", "toolbar=1,scrollbars=1,resizable=1,statusbar=1,menubar=1,width=640,height=400,top=0,left=0");
}

//view function
function doViewImage() {
    window.open("systemMenuMaintenance.do?pageEvent=viewMenuGroupImage", "wdis", "toolbar=1,scrollbars=1,resizable=1,statusbar=1,menubar=1,width=640,height=400,top=0,left=0");
}

function doLoad() {
	<%
	if (CommonUtil.nullToString((String)session.getAttribute(ProjectConstants.SESSION_ALERT_AFTER_SAVE)).equals(ProjectConstants.GENERIC_YES)) {
		session.removeAttribute(ProjectConstants.SESSION_ALERT_AFTER_SAVE);
		out.println("alert('Record saved.');");
	}
	String lastAction = (String) systemMenuMaintenanceForm.getPageEvent();
	if (lastAction != null && lastAction.startsWith("pEditRemark")) {
		out.println("window.open('remarkText.do','textWin','width=520,height=250,resizable=no,menubar=no,scrollbars=yes,status=no');");
	} else if (lastAction != null  && lastAction.equalsIgnoreCase("addMenuGroupIcon")) {
		out.println("window.open('uploadFile.do','uploadWin','width=800,height=600,resizable=yes,menubar=no,scrollbars=yes,status=no');");
	} else if (lastAction != null  && lastAction.equalsIgnoreCase("addMenuGroupImage")) {
		out.println("window.open('uploadFile.do','uploadWin','width=800,height=600,resizable=yes,menubar=no,scrollbars=yes,status=no');");
	}


	%>
}

function changeVal(form, name, index, val) {
        //check is array or not
        if(form.elements[name].length == null){
                form.elements[name].value = val;
        } else {
                //array
                form.elements[name][index].value = val;
        }
}


var isSubmitted = 0;
function doSubmit(event, val) {
	if (isSubmitted == 0) {
		if(event == "exit"){
			if(!confirmExit("")){
				return false;
			}
		}
		isSubmitted = 1;
		document.forms[0].pageEvent.value = event;
		if (val != null) {
			document.forms[0].pageEventSrc.value = val;
		}
		document.forms[0].submit();
	}
}
</script>

<body onLoad="javascript:doLoad();">

<html:form action="/systemMenuMaintenance">
<html:hidden property="pageEventSrc" />
<html:hidden property="pageEvent" />
<html:hidden property="pageMode" />

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
    <td>
	<chtml:button form="systemMenuMaintenanceForm" pageEvent="exit" styleClass="button1" />
	<chtml:button form="systemMenuMaintenanceForm" pageEvent="save" styleClass="button1" />
	<chtml:button form="systemMenuMaintenanceForm" pageEvent="search" styleClass="button1" />
<%--
	<chtml:button form="systemMenuMaintenanceForm" pageEvent="create" styleClass="button1" />
--%>
	<logic:equal name="systemMenuMaintenanceForm" property="pageMode" value="modify">	
		<chtml:button form="systemMenuMaintenanceForm" pageEvent="refresh" styleClass="button1" />
<%--
		<chtml:button form="systemMenuMaintenanceForm" pageEvent="delete" styleClass="button1" />
--%>
	</logic:equal>
    </td>
</tr>
</table>

<font color='red'><html:errors /></font>

<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
    <td width="150" class="col_label">			
		<bean:message key="label.general.mandatory.field"/>
		<span class="mandatory_label">Menu Group ID:</span>
	</td>
    <td class="col_value">
	<logic:equal name="systemMenuMaintenanceForm" property="pageMode" value="create">
		<select name="groupId" class="t2">
		<% String where2 = "REF_MASTER_CODE ='" + ProjectConstants.CD_MENU_GROUP + "' AND REF_STATUS = '"+ProjectConstants.GENERIC_ACTIVE+"' ";%>
		<chtml:options table="T_CODE_DTL"
					valuecolumn="REF_CODE"
					textcolumn="REF_CODE"
					where= "<%=where2%>"
					order="REF_CODE"
					selected="<%=systemMenuMaintenanceForm.getGroupId()%>" />
		</select>
	</logic:equal>
	<logic:notEqual name="systemMenuMaintenanceForm" property="pageMode" value="create">
	    <bean:write name="systemMenuMaintenanceForm" property="groupId" filter="true"/>
	    <html:hidden property="groupId"/>
	</logic:notEqual>
	</td>
</tr>
<tr>
    <td width="150" class="col_label">Menu Name:</td>
    <td class="col_value">
	    <html:text property="menuName" size="20" maxlength="60" styleClass="t2" />
		</td>
</tr>
<tr>
    <td width="150" class="col_label">
		<bean:message key="label.general.mandatory.field"/>
		<span class="mandatory_label">Menu ID:</span>
	</td>
    <td class="col_value">
	<logic:equal name="systemMenuMaintenanceForm" property="pageMode" value="create">
	    <html:text property="menuId" size="20" maxlength="30" styleClass="t2" />
	</logic:equal>
	<logic:notEqual name="systemMenuMaintenanceForm" property="pageMode" value="create">
	    <bean:write name="systemMenuMaintenanceForm" property="menuId" filter="true"/>
	    <html:hidden property="menuId"/>
	</logic:notEqual>
	<html:hidden property="companyCode"/>
	</td>
</tr>
<tr>
<%
String menuType = systemMenuMaintenanceForm.getMenuType();
String menuSelected = "";
String itemSelected = "";

if(ProjectConstants.MENU_TYPE_MENU.equalsIgnoreCase(menuType)){
	menuSelected = "selected";
} else if(ProjectConstants.MENU_TYPE_ITEM.equalsIgnoreCase(menuType)){
	itemSelected = "selected";
}
%>
    <td width="150" class="col_label">Menu Type:</td>
    <td class="col_value">
		<select name="menuType" class="t2">
			<option value="<%=ProjectConstants.MENU_TYPE_MENU%>" <%=menuSelected%>>Menu</option>
			<option value="<%=ProjectConstants.MENU_TYPE_ITEM%>" <%=itemSelected%>>Item</option>
		</select>
	</td>
</tr>
<tr>
    <td width="150" class="col_label">Menu Order:</td>
    <td class="col_value">
	    <html:text property="menuOrder" size="5" maxlength="3" styleClass="t2" />
		</td>
</tr>
<tr>
    <td width="150" class="col_label">Menu Url:</td>
    <td class="col_value">
		<logic:equal name="systemMenuMaintenanceForm" property="pageMode" value="create">
			<html:text property="menuUrl" size="20" maxlength="60" styleClass="t2" />
		</logic:equal>
		<logic:notEqual name="systemMenuMaintenanceForm" property="pageMode" value="create">
			<bean:write name="systemMenuMaintenanceForm" property="menuUrl" filter="true"/>
		</logic:notEqual>
	</td>
</tr>
<tr>
    <td width="150" class="col_label">Parent Menu Id:</td>
    <td class="col_value">
	<% 
		String where = "COMPANY_CODE = '" + WebUtil.getAppropriateCompanyCode(session, null) + "' AND MENU_TYPE='M'"; 
		String selected1 = "";
		String selected2 = "";
		String selected3 = "";
		String selected4 = "";
		String parentMenuId = systemMenuMaintenanceForm.getParentMenuId();
		if(ProjectConstants.PARENT_MENU_ALERT_LIST.equals(parentMenuId)){
			selected1 = "selected";
		} else if(ProjectConstants.PARENT_MENU_TODO_LIST.equals(parentMenuId)){
			selected2 = "selected";
		} else if(ProjectConstants.PARENT_MENU_MENU_TAB.equals(parentMenuId)){
			selected3 = "selected";
		} else if(ProjectConstants.PARENT_MENU_ENQ_TAB.equals(parentMenuId)){
			selected4 = "selected";
		}
	%>
	<select name="parentMenuId" class="t2">
		<option value=""></option>
		<option value="<%=ProjectConstants.PARENT_MENU_MENU_TAB%>" <%=selected3%>><%=ProjectConstants.PARENT_MENU_MENU_TAB%></option>						
		<option value="<%=ProjectConstants.PARENT_MENU_ENQ_TAB%>" <%=selected4%>><%=ProjectConstants.PARENT_MENU_ENQ_TAB%></option>	
		<option value="<%=ProjectConstants.PARENT_MENU_ALERT_LIST%>" <%=selected1%>><%=ProjectConstants.PARENT_MENU_ALERT_LIST%></option>						
		<option value="<%=ProjectConstants.PARENT_MENU_TODO_LIST%>" <%=selected2%>><%=ProjectConstants.PARENT_MENU_TODO_LIST%></option>	
			<chtml:options table="T_MENU_GROUP"
						valuecolumn="MENU_ID"
						textcolumn="MENU_NAME"
						order="MENU_NAME" 
						where="<%=where%>"
						selected="<%= systemMenuMaintenanceForm.getParentMenuId() %>" />
		</select>
    </td>
</tr>

<tr>
    <td width="150" class="col_label">Root Menu Id:</td>
    <td class="col_value">
	<% 
		selected1 = "";
		selected2 = "";
		String rootMenuId = systemMenuMaintenanceForm.getRootMenuId();
		if(ProjectConstants.PARENT_MENU_MENU_TAB.equals(rootMenuId)){
			selected1 = "selected";
		} else if(ProjectConstants.PARENT_MENU_ENQ_TAB.equals(rootMenuId)){
			selected2 = "selected";
		}
	%>
	<select name="rootMenuId" class="t2">
		<option value="<%=ProjectConstants.PARENT_MENU_MENU_TAB%>" <%=selected1%>><%=ProjectConstants.PARENT_MENU_MENU_TAB%></option>						
		<option value="<%=ProjectConstants.PARENT_MENU_ENQ_TAB%>" <%=selected2%>><%=ProjectConstants.PARENT_MENU_ENQ_TAB%></option>	
		</select>
    </td>
</tr>

<tr>
	<td class="col_label">Menu Icon:</td>
	<td class="col_value">
		<% if (systemMenuMaintenanceForm.getMenuIcon() != null){ %>
			<input type="button" value="View.." class="button1" onClick="javascript:doViewIcon();">
			<input type="button" value="Del.." class="button1" onClick="javascript:doSubmit('delMenuGroupIcon');">
		<% } else { %>
			<input type="button" value="Add.." class="button1" onClick="javascript:doSubmit('addMenuGroupIcon');">
		<% } %>
	</td>
</tr>
<tr>
	<td class="col_label">Menu Image:</td>
	<td class="col_value">
		<% if (systemMenuMaintenanceForm.getMenuImage() != null){ %>
			<input type="button" value="View.." class="button1" onClick="javascript:doViewImage();">
			<input type="button" value="Del.." class="button1" onClick="javascript:doSubmit('delMenuGroupImage');">
		<% } else { %>
			<input type="button" value="Add.." class="button1" onClick="javascript:doSubmit('addMenuGroupImage');">
		<% } %>
	</td>
</tr>
<%if(Logger.getLogLevel() > Logger.LOG_LEVEL_DEBUG) { %>
<tr>
	<td class="col_label">Status:</td>
	<td class="col_value">
		<select name="status" class="selectBox1">
			<%where = " TYPE = '" +  ProjectConstants.CONSTANT_TYPE_ACT_INACT + "' ";%>
			<option value="">
			<chtml:options table="T_SYS_CONSTANTS"
			valuecolumn="CONSTANT_CODE"
			textcolumn="CONSTANT_NAME"
			where= "<%=where%>"
			order="CONSTANT_NAME"
			selected="<%=systemMenuMaintenanceForm.getStatus()%>"
			 />
		</select>
	</td>
</tr>
<% } %>

</table>


<logic:equal name="systemMenuMaintenanceForm" property="folderIdx" value="0" >
<br><br>
<input type="button" value="Add Menu Object" class="button1" onClick="javascript:doSubmit('addMenuObject');">
	
<table bordercolor="#808080" cellspacing=1 cellpadding=2 width=859 border=0>
	<tr>
		<td width="10%" class="grid_header">&nbsp</td>
		<td width="20%" class="grid_header">
			<bean:message key="label.general.mandatory.field"/>
			<span class="mandatory_label">Object ID:</span>
		</td>
		<td width="20%" class="grid_header">Object Name</td>
		<td width="20%" class="grid_header">Object Type</td>
		<td width="10%" class="grid_header">Object Action</td>
	</tr>
<% int displayIdx = 0; %>
<logic:iterate id="menuObjectRow" name="menuObjectList" indexId="idx"  >
<%
    SystemMenuObjectRow menuObject = (SystemMenuObjectRow) menuObjectRow;
%>
<%
if (CommonUtil.isEmpty(menuObject.getIsDelete())) {
%>
<tr <%=(idx.intValue()%2 == 0)? "class=grid_result1": "class=grid_result2"%>> 
    <td>
	<%--
		<input type="button" value="Del" onClick="javascript:doSubmit('delMenuObject', '<%= idx %>');" class="button1" />
	--%>
	&nbsp;
	</td>

<%
	if (menuObject.getRowMode().equals("MODE_MODIFY")){
%>
		<td class="t2">
			<%= CommonUtil.nullToString(menuObject.getObjectId()) %>
			<html:hidden property="objectId" value="<%= CommonUtil.nullToString(menuObject.getObjectId()) %>" />
			<html:hidden property="idx" value="<%=menuObject.getIdx()%>" />
			<html:hidden property="rowMode"  value="<%=menuObject.getRowMode()%>"/>
		</td>
	<%
	} else if (menuObject.getRowMode().equals("MODE_CREATE")) {
	%>
		<td class="t2">
			<html:text property="objectId" maxlength="30" size="30" value="<%= CommonUtil.nullToString(menuObject.getObjectId()) %>" styleClass="t2" />
			<html:hidden property="idx" value="<%=menuObject.getIdx()%>" />
			<html:hidden property="rowMode"  value="<%=menuObject.getRowMode()%>"/>
		</td>
	<%
	}
	%>
	<td class="t2">
		  <html:text property="objectName" maxlength="30" value="<%= CommonUtil.nullToString(menuObject.getObjectName()) %>" />
	</td>
	<td class="t2">
		  <html:text property="objectType" maxlength="30" value="<%= CommonUtil.nullToString(menuObject.getObjectType()) %>" />
	</td>
	<td class="t2">
			<html:text property="objectAction" maxlength="30" value="<%= CommonUtil.nullToString(menuObject.getObjectAction()) %>" />
	</td>
</tr>
<%
} else {
%>
	<html:hidden property="idx" value="<%=menuObject.getIdx()%>" />
	<html:hidden property="isDelete" value="<%=menuObject.getIdx()%>" />
	<html:hidden property="objectId" value="<%= menuObject.getObjectId() %>" />
	<html:hidden property="rowMode"  value="<%=menuObject.getRowMode()%>"/>
<%
}
%>
</logic:iterate>
</table
>
</logic:equal>


</html:form>